<template>
    <!-- 添加或修改报工信息数据对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="80%" append-to-body :close-on-click-modal="false" v-dialogDrag>
        <el-form ref="form" :model="form" :rules="rules" label-width="120px">
            <el-tabs v-model="activeName" class="detail-tab" type="card">
                <el-tab-pane label="基本信息" name="first">
                    <el-row :gutter="20">
                        <!--<el-col :span="12">
                            <el-form-item label="项目id" prop="projectId">
                                <el-input v-model="form.projectId" placeholder="请输入项目id"/>
                            </el-form-item>
                        </el-col>
                        <el-col :span="12">
                            <el-form-item label="订单id" prop="orderId">
                                <el-input v-model="form.orderId" placeholder="请输入订单id"/>
                            </el-form-item>
                        </el-col>
                        <el-col :span="12">
                            <el-form-item label="产品id" prop="goodsId">
                                <el-input v-model="form.goodsId" placeholder="请输入产品id"/>
                            </el-form-item>
                        </el-col>
                        <el-col :span="12">
                            <el-form-item label="生产批号" prop="batchNumber">
                                <el-input v-model="form.batchNumber" placeholder="请输入生产批号"/>
                            </el-form-item>
                        </el-col>
                        <el-col :span="12">
                            <el-form-item label="系统推送" prop="processMethod">
                                <el-input v-model="form.processMethod" placeholder="请输入系统推送"/>
                            </el-form-item>
                        </el-col>-->
                        <el-col :span="12">
                            <el-form-item label="加工件数" prop="processCount">
                                <el-input v-model="form.processCount" placeholder="请输入加工件数"/>
                            </el-form-item>
                        </el-col>
                        <el-col :span="12">
                            <el-form-item label="生产完成时间" prop="finishTime">
                                <el-date-picker clearable
                                                v-model="form.finishTime"
                                                type="date"
                                                value-format="yyyy-MM-dd"
                                                placeholder="请选择生产完成时间">
                                </el-date-picker>
                            </el-form-item>
                        </el-col>
                        <el-col :span="12">
                            <el-form-item label="采购方总部编码" prop="purchaserHqCode">
                                <el-input v-model="form.purchaserHqCode" placeholder="请输入采购方总部编码"/>
                            </el-form-item>
                        </el-col>
                        <el-col :span="12">
                            <el-form-item label="供应商编码" prop="supplierCode">
                                <el-input v-model="form.supplierCode" placeholder="请输入供应商编码"/>
                            </el-form-item>
                        </el-col>
                        <el-col :span="12">
                            <el-form-item label="生产订单编号" prop="ipoNo">
                                <el-input v-model="form.ipoNo" placeholder="请输入生产订单编号"/>
                            </el-form-item>
                        </el-col>
                       <!-- <el-col :span="12">
                            <el-form-item label="产品内部ID号" prop="insideNo">
                                <el-input v-model="form.insideNo" placeholder="请输入产品内部ID号"/>
                            </el-form-item>
                        </el-col>-->
                        <el-col :span="12">
                            <el-form-item label="设备编号" prop="deviceNo">
                                <el-input v-model="form.deviceNo" placeholder="请输入设备编号"/>
                            </el-form-item>
                        </el-col>
                        <el-col :span="12">
                            <el-form-item label="生产批次号" prop="productBatchNo">
                                <el-input v-model="form.productBatchNo" placeholder="请输入生产批次号"/>
                            </el-form-item>
                        </el-col>
                        <el-col :span="12">
                            <el-form-item label="工序名称" prop="processName">
                                <el-input v-model="form.processName" placeholder="请输入工序名称"/>
                            </el-form-item>
                        </el-col>
                        <el-col :span="12">
                            <el-form-item label="品类编码" prop="categoryCode">
                                <el-input v-model="form.categoryCode" placeholder="请输入品类编码"/>
                            </el-form-item>
                        </el-col>
                        <el-col :span="12">
                            <el-form-item label="种类编码" prop="subclassCode">
                                <el-input v-model="form.subclassCode" placeholder="请输入种类编码"/>
                            </el-form-item>
                        </el-col>
                        <el-col :span="12">
                            <el-form-item label="工序编码" prop="processCode">
                                <el-input v-model="form.processCode" placeholder="请输入工序编码"/>
                            </el-form-item>
                        </el-col>
                        <el-col :span="12">
                            <el-form-item label="生产工艺路线编码" prop="processNo">
                                <el-input v-model="form.processNo" placeholder="请输入生产工艺路线编码"/>
                            </el-form-item>
                        </el-col>
                       <!-- <el-col :span="12">
                            <el-form-item label="生产车间id" prop="workshopId">
                                <el-input v-model="form.workshopId" placeholder="请输入生产车间id"/>
                            </el-form-item>
                        </el-col>-->
                        <el-col :span="12">
                            <el-form-item label="生产车间编码" prop="workshopCode">
                                <el-input v-model="form.workshopCode" placeholder="请输入生产车间编码"/>
                            </el-form-item>
                        </el-col>
                        <el-col :span="12">
                            <el-form-item label="生产车间名称" prop="workshopName">
                                <el-input v-model="form.workshopName" placeholder="请输入生产车间名称"/>
                            </el-form-item>
                        </el-col>
                        <el-col :span="12">
                            <el-form-item label="生产工单编号" prop="woNo">
                                <el-input v-model="form.woNo" placeholder="请输入生产工单编号"/>
                            </el-form-item>
                        </el-col>
                       <!-- <el-col :span="12">
                            <el-form-item label="实物id，如国网实物id" prop="productId">
                                <el-input v-model="form.productId" placeholder="请输入实物id，如国网实物id"/>
                            </el-form-item>
                        </el-col>
                        <el-col :span="12">
                            <el-form-item label="数据来源" prop="dataSource">
                                <el-input v-model="form.dataSource" placeholder="请输入数据来源"/>
                            </el-form-item>
                        </el-col>
                        <el-col :span="12">
                            <el-form-item label="来源数据创建时间" prop="dataSourceCreateTime">
                                <el-input v-model="form.dataSourceCreateTime" placeholder="请输入来源数据创建时间"/>
                            </el-form-item>
                        </el-col>-->
                        <el-col :span="12">
                            <el-form-item label="计划开始时间" prop="planStartTime">
                                <el-input v-model="form.planStartTime" placeholder="请输入计划开始时间"/>
                            </el-form-item>
                        </el-col>
                        <el-col :span="12">
                            <el-form-item label="计划结束时间" prop="planEndTime">
                                <el-input v-model="form.planEndTime" placeholder="请输入计划结束时间"/>
                            </el-form-item>
                        </el-col>
                        <el-col :span="12">
                            <el-form-item label="实际开始时间" prop="actualStartDate">
                                <el-input v-model="form.actualStartDate" placeholder="请输入实际开始时间"/>
                            </el-form-item>
                        </el-col>
                        <el-col :span="12">
                            <el-form-item label="实际结束时间" prop="actualFinishDate">
                                <el-input v-model="form.actualFinishDate" placeholder="请输入实际结束时间"/>
                            </el-form-item>
                        </el-col>
                        <el-col :span="12">
                            <el-form-item label="客户所属省份" prop="buyerProvince">
                                <el-input v-model="form.buyerProvince" placeholder="请输入客户所属省份"/>
                            </el-form-item>
                        </el-col>
                        <!--<el-col :span="12">
                            <el-form-item label="数据拥有方" prop="ownerId">
                                <el-input v-model="form.ownerId" placeholder="请输入数据拥有方"/>
                            </el-form-item>
                        </el-col>
                        <el-col :span="12">
                            <el-form-item label="数据可见方" prop="openId">
                                <el-input v-model="form.openId" placeholder="请输入数据可见方"/>
                            </el-form-item>
                        </el-col>-->
                    </el-row>
                </el-tab-pane>
            </el-tabs>
        </el-form>
        <div slot="footer" class="dialog-footer">
            <el-button type="primary" @click="submitForm">确 定</el-button>
            <el-button @click="cancel">取 消</el-button>
        </div>
    </el-dialog>
</template>

<script>
    import { addAction, getById, updateAction } from '@/api/manage';
    import moment from 'moment';

    export default {
        name: "FactoryProductBaogongForm",
        data() {
            return {
                // 遮罩层
                loading: true,
                activeName: "first",
                // 弹出层标题
                title: "",
                // 是否显示弹出层
                open: false,
                // 表单参数
                form: {},
                // 表单校验
                rules: {
                },
                url: {
                    getById:'/factoryProductBaogong/factoryProductBaogong/',
                    add:'/factoryProductBaogong/factoryProductBaogong/add',
                    edit:'/factoryProductBaogong/factoryProductBaogong/edit',
                },
            };
        },
        created() {

        },
        methods: {
            // 取消按钮
            cancel() {
                this.open = false;
                this.reset();
            },
            // 表单重置
            reset() {
                this.form = {
                  id: null,
                  projectId: null,
                  orderId: null,
                  goodsId: null,
                  batchNumber: null,
                  processMethod: null,
                  processCount: null,
                  finishTime: null,
                  createBy: null,
                  createTime: null,
                  updateBy: null,
                  updateTime: null,
                  delFlag: null,
                  purchaserHqCode: null,
                  supplierCode: null,
                  ipoNo: null,
                  insideNo: null,
                  deviceNo: null,
                  productBatchNo: null,
                  processName: null,
                  categoryCode: "60",
                  subclassCode: "60004",
                  processCode: null,
                  processNo: null,
                  workshopId: null,
                  workshopCode: null,
                  workshopName: null,
                  woNo: null,
                  productId: null,
                  dataSource: null,
                  dataSourceCreateTime: null,
                  planStartTime: null,
                  planEndTime: null,
                  actualStartDate: null,
                  actualFinishDate: null,
                  orderStatus: "0",
                  buyerProvince: null,
                  ownerId: null,
                  openId: null,
                  wavyStatus: "0",
                  projectCode: null,
                  planId: null,
                  planCode: null,
                  workId: null,
                  workCode: null,
                  gongxuId: null,
                  gongxuCode: null,
                  goodsId: null,
                  goodsCode: null,
                };
                this.resetForm("form");
            },
            /** 新增按钮操作 */
            handleAdd(projectId,projectCode,planCode, ipoNo, workId, workCode, gongxuId, gongxuCode, goodsId, goodsCode) {
                this.reset();
                this.form.projectId=projectId;
                this.form.projectCode=projectCode;
                this.form.planCode=planCode;
                this.form.ipoNo=ipoNo;
                this.form.workId=workId;
                this.form.workCode=workCode;
                this.form.gongxuId=gongxuId;
                this.form.gongxuCode=gongxuCode;
                this.form.goodsId=goodsId;
                this.form.goodsCode=goodsCode;
                this.open = true;
                this.title = "添加报工信息数据";
            },
            /** 修改按钮操作 */
            handleUpdate(row) {
                this.reset();
                const id = row.id || this.ids;
                getById(this.url.getById, id).then(response => {
                    this.form = response.data;
                    this.open = true;
                    this.title = "修改报工信息数据";
                });
            },
            /** 提交按钮 */
            submitForm() {
                this.$refs["form"].validate(valid => {
                    if (valid) {
                        if (this.form.id != null) {
                            updateAction(this.url.edit, this.form).then(response => {
                                this.$modal.msgSuccess("修改成功");
                                this.open = false;
                                this.$emit('ok');
                            });
                        } else {
                            addAction(this.url.add, this.form).then(response => {
                                this.$modal.msgSuccess("新增成功");
                                this.open = false;
                                this.$emit('ok');
                            });
                        }
                    }
                });
            },
        }
    };
</script>
